home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / dfue / term 4.6(?) / extras / source / term-source.lha / Dial.c < prev    next >
C/C++ Source or Header  |  1996-03-18  |  42KB  |  1,863 lines

  1. /*
  2. **    Dial.c
  3. **
  4. **    The dialing routine as called by the phonebook
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* Panel gadget IDs. */
  17.  
  18. enum    {    GAD_CALLING=1,GAD_TIME,GAD_NOTE,
  19.             GAD_SKIP,GAD_REMOVE,GAD_ONLINE,GAD_ABORT
  20.         };
  21.  
  22. STATIC VOID __stdargs
  23. DialPrintBox(LayoutHandle *Handle,LONG Box,LONG Line,STRPTR String,...)
  24. {
  25.     UBYTE     LocalBuffer[256];
  26.     va_list     VarArgs;
  27.  
  28.     va_start(VarArgs,String);
  29.     VSPrintf(LocalBuffer,String,VarArgs);
  30.     va_end(VarArgs);
  31.  
  32.     LT_SetAttributes(Handle,Box,
  33.         LABX_Index,    Line,
  34.         LABX_Text,    LocalBuffer,
  35.     TAG_DONE);
  36. }
  37.  
  38. STATIC BOOL
  39. SendSomeCommand(LayoutHandle *Handle,STRPTR Command,STRPTR Message,STRPTR ErrorMessage)
  40. {
  41.     DialPrintBox(Handle,GAD_NOTE,0,Message);
  42.  
  43.     FlowInit(TRUE);
  44.  
  45.     SerialCommand(Command);
  46.  
  47.     DelayTime(1,0);
  48.  
  49.     HandleSerial();
  50.  
  51.     if(FlowInfo . Changed && FlowInfo . Error)
  52.     {
  53.         DialPrintBox(Handle,GAD_NOTE,0,ErrorMessage);
  54.  
  55.         WakeUp(Handle -> Window,SOUND_ERROR);
  56.  
  57.         return(TRUE);
  58.     }
  59.     else
  60.         return(FALSE);
  61. }
  62.  
  63.     /* BuildName(STRPTR Name):
  64.      *
  65.      *    Build a file name from a BBS name and the current date.
  66.      */
  67.  
  68. STATIC VOID
  69. BuildName(STRPTR Name,STRPTR Date)
  70. {
  71.     if(Date[0])
  72.     {
  73.         LONG    NameLen = strlen(Name),
  74.                 DateLen = strlen(Date),
  75.                 Delta;
  76.  
  77.         if((Delta = NameLen + 1 + DateLen - 32) > 0)
  78.             Name[NameLen - Delta] = 0;
  79.  
  80.         strcat(Name,"_");
  81.         strcat(Name,Date);
  82.     }
  83. }
  84.  
  85.     /* OpenAutoCaptureFile(STRPTR SomeName):
  86.      *
  87.      *    Open a capture file.
  88.      */
  89.  
  90. STATIC VOID
  91. OpenAutoCaptureFile(STRPTR SomeName)
  92. {
  93.     UBYTE            SharedBuffer[MAX_FILENAME_LENGTH],
  94.                     Name[50],
  95.                     Date[20],
  96.                     Time[20];
  97.     struct DateTime    DateTime;
  98.  
  99.         /* Get the current time and date. */
  100.  
  101.     DateStamp(&DateTime . dat_Stamp);
  102.  
  103.         /* Prepare for date conversion. */
  104.  
  105.     DateTime . dat_Format    = FORMAT_DOS;
  106.     DateTime . dat_Flags    = 0;
  107.     DateTime . dat_StrDay    = NULL;
  108.     DateTime . dat_StrDate    = Date;
  109.     DateTime . dat_StrTime    = Time;
  110.  
  111.         /* Convert the date. */
  112.  
  113.     if(DateToStr(&DateTime))
  114.     {
  115.             /* Remember the BBS name. */
  116.  
  117.         strcpy(Name,SomeName);
  118.  
  119.             /* Append the creation date if necessary. */
  120.  
  121.         if(Config -> CaptureConfig -> AutoCaptureDate == AUTOCAPTURE_DATE_NAME)
  122.             BuildName(Name,Date);
  123.  
  124.             /* Make it a reasonable name. */
  125.  
  126.         FixName(Name);
  127.  
  128.             /* Get the capture file path. */
  129.  
  130.         strcpy(SharedBuffer,Config -> CaptureConfig -> CapturePath);
  131.  
  132.             /* Try to build a valid file and path name. */
  133.  
  134.         if(AddPart(SharedBuffer,Name,MAX_FILENAME_LENGTH))
  135.         {
  136.                 /* Is the capture file still open? */
  137.  
  138.             if(FileCapture)
  139.             {
  140.                     /* Close the file. */
  141.  
  142.                 BufferClose(FileCapture);
  143.  
  144.                 FileCapture = NULL;
  145.  
  146.                     /* Any data written? */
  147.  
  148.                 if(!GetFileSize(CaptureName))
  149.                     DeleteFile(CaptureName);
  150.                 else
  151.                 {
  152.                     AddProtection(CaptureName,FIBF_EXECUTE);
  153.  
  154.                     if(Config -> MiscConfig -> CreateIcons)
  155.                         AddIcon(CaptureName,FILETYPE_TEXT,TRUE);
  156.                 }
  157.             }
  158.  
  159.                 /* Try to append the new data. */
  160.  
  161.             if(FileCapture = BufferOpen(SharedBuffer,"a"))
  162.             {
  163.                     /* Set the menu checkmark. */
  164.  
  165.                 CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  166.  
  167.                     /* Remember the current capture file name. */
  168.  
  169.                 strcpy(CaptureName,SharedBuffer);
  170.  
  171.                     /* Add the creation date if necessary. */
  172.  
  173.                 if(Config -> CaptureConfig -> AutoCaptureDate == AUTOCAPTURE_DATE_INCLUDE)
  174.                 {
  175.                     UBYTE DateTimeBuffer[256];
  176.  
  177.                     if(FormatStamp(&DateTime . dat_Stamp,NULL,NULL,DateTimeBuffer,FALSE))
  178.                         BPrintf(FileCapture,LocaleString(MSG_DIALPANEL_FILE_CREATED_TXT),DateTimeBuffer);
  179.                 }
  180.             }
  181.             else
  182.                 CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  183.  
  184.             ConOutputUpdate();
  185.         }
  186.     }
  187. }
  188.  
  189.     /* Connect(struct PhoneNode *DialNode,STRPTR NumberBuffer):
  190.      *
  191.      *    Perform connect action(s).
  192.      */
  193.  
  194. STATIC VOID
  195. Connect(struct PhoneNode *DialNode,STRPTR NumberBuffer)
  196. {
  197.     ULONG OnlinePlus;
  198.  
  199.     if(DialNode -> Entry)
  200.     {
  201.         UpdateConfig(DialNode -> Entry -> Config,Config);
  202.  
  203.         ConfigChanged = FALSE;
  204.  
  205.         MakeCall(DialNode -> Entry -> Header -> Name,NumberBuffer);
  206.  
  207.         ObtainSemaphoreShared(&PatternSemaphore);
  208.  
  209.         ChosenPattern    = FindTimeDate(PatternList,NumberBuffer);
  210.         ChosenEntry        = DialNode -> Entry;
  211.  
  212.         SendStartup        = TRUE;
  213.  
  214.         ReleaseSemaphore(&PatternSemaphore);
  215.  
  216.         strcpy(Password,DialNode -> Entry -> Header -> Password);
  217.         strcpy(UserName,DialNode -> Entry -> Header -> UserName);
  218.  
  219.         strcpy(CurrentBBSName,DialNode -> Entry -> Header -> Name);
  220.         strcpy(CurrentBBSComment,DialNode -> Entry -> Header -> Comment);
  221.  
  222.         strcpy(CurrentBBSNumber,NumberBuffer);
  223.  
  224.         if(DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  225.         {
  226.             OnlinePlus = DialNode -> Entry -> Config -> ModemConfig -> TimeToConnect;
  227.  
  228.             if(DialNode -> Entry -> Config -> ModemConfig -> ConnectLimit > 0 && DialNode -> Entry -> Config -> ModemConfig -> ConnectLimitMacro[0])
  229.             {
  230.                 LimitCount = DialNode -> Entry -> Config -> ModemConfig -> ConnectLimit;
  231.  
  232.                 strcpy(LimitMacro,DialNode -> Entry -> Config -> ModemConfig -> ConnectLimitMacro);
  233.             }
  234.             else
  235.                 LimitCount = -1;
  236.         }
  237.         else
  238.         {
  239.             OnlinePlus = Config -> ModemConfig -> TimeToConnect;
  240.  
  241.             if(Config -> ModemConfig -> ConnectLimit > 0 && Config -> ModemConfig -> ConnectLimitMacro[0])
  242.             {
  243.                 LimitCount = Config -> ModemConfig -> ConnectLimit;
  244.  
  245.                 strcpy(LimitMacro,Config -> ModemConfig -> ConnectLimitMacro);
  246.             }
  247.             else
  248.                 LimitCount = -1;
  249.         }
  250.  
  251.         LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_1_TXT),DialNode -> Entry -> Header -> Name,NumberBuffer);
  252.     }
  253.     else
  254.     {
  255.         OnlinePlus = Config -> ModemConfig -> TimeToConnect;
  256.  
  257.         MakeCall("???",NumberBuffer);
  258.  
  259.         ObtainSemaphoreShared(&PatternSemaphore);
  260.  
  261.         ChosenPattern    = FindTimeDate(PatternList,NumberBuffer);
  262.         ChosenEntry        = NULL;
  263.  
  264.         ReleaseSemaphore(&PatternSemaphore);
  265.  
  266.         Password[0]    = 0;
  267.         UserName[0]    = 0;
  268.         SendStartup    = FALSE;
  269.  
  270.         CurrentBBSName[0]    = 0;
  271.         CurrentBBSComment[0]    = 0;
  272.  
  273.         strcpy(CurrentBBSNumber,NumberBuffer);
  274.  
  275.         if(Config -> ModemConfig -> ConnectLimit > 0 && Config -> ModemConfig -> ConnectLimitMacro[0])
  276.         {
  277.             LimitCount = Config -> ModemConfig -> ConnectLimit;
  278.  
  279.             strcpy(LimitMacro,Config -> ModemConfig -> ConnectLimitMacro);
  280.         }
  281.         else
  282.             LimitCount = -1;
  283.  
  284.         LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_2_TXT),NumberBuffer);
  285.     }
  286.  
  287.         /* We are now online. */
  288.  
  289.     SetOnlineState(TRUE);
  290.  
  291.         // Start the accounting process
  292.  
  293.     StartAccountant(OnlinePlus);
  294.  
  295.         /* Open auto-capture file. */
  296.  
  297.     if(Config -> CaptureConfig -> ConnectAutoCapture && Config -> CaptureConfig -> CapturePath[0])
  298.     {
  299.         if(DialNode -> Entry)
  300.             OpenAutoCaptureFile(DialNode -> Entry -> Header -> Name);
  301.         else
  302.             OpenAutoCaptureFile(LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT));
  303.     }
  304.  
  305.         /* Remove node from
  306.          * dialing list and
  307.          * perform system
  308.          * setup.
  309.          */
  310.  
  311.     if(DialNode -> Entry)
  312.         RemoveDialNode(DialNode);
  313.  
  314.     Remove(&DialNode -> VanillaNode);
  315.  
  316.     FreeVecPooled(DialNode);
  317.  
  318.     if(PrivateConfig -> MiscConfig -> BackupConfig)
  319.     {
  320.         if(!BackupConfig)
  321.         {
  322.             if(BackupConfig = CreateConfiguration(TRUE))
  323.                 SaveConfig(PrivateConfig,BackupConfig);
  324.         }
  325.     }
  326.  
  327.         /* Make sure that the following
  328.          * setup/initialization will not
  329.          * touch the serial configuration.
  330.          */
  331.  
  332.     CopyMem(Config -> SerialConfig,PrivateConfig -> SerialConfig,sizeof(struct SerialSettings));
  333.  
  334.     ConfigSetup();
  335.  
  336.         /* Reset the scanner. */
  337.  
  338.     FlowInit(TRUE);
  339. }
  340.  
  341.     /* OpenDialPanel(BOOL *Record):
  342.      *
  343.      *    Open the dialing panel.
  344.      */
  345.  
  346. STATIC LayoutHandle *
  347. OpenDialPanel(BOOL *Record)
  348. {
  349.     LayoutHandle *Handle;
  350.  
  351.     if(Handle = LT_CreateHandleTags(Window -> WScreen,
  352.         LH_LocaleHook,    &LocaleHook,
  353.     TAG_DONE))
  354.     {
  355.         LT_New(Handle,
  356.             LA_Type,    VERTICAL_KIND,
  357.         TAG_DONE);
  358.         {
  359.             LT_New(Handle,
  360.                 LA_Type,    VERTICAL_KIND,
  361.             TAG_DONE);
  362.             {
  363.                 LT_New(Handle,
  364.                     LA_Type,    VERTICAL_KIND,
  365.                 TAG_DONE);
  366.                 {
  367.                     LT_New(Handle,
  368.                         LA_Type,            BOX_KIND,
  369.                         LA_ID,                GAD_CALLING,
  370.                         LA_Chars,            45,
  371.                         LA_Lines,            4,
  372.                         LABX_ReserveSpace,    TRUE,
  373.                         LABX_FirstLabel,    MSG_DIALPANEL_CALLING_TXT,
  374.                         LABX_LastLabel,        MSG_DIALPANEL_NEXT_TXT,
  375.                     TAG_DONE);
  376.  
  377.                     LT_New(Handle,
  378.                         LA_Type,            BOX_KIND,
  379.                         LA_ID,                GAD_TIME,
  380.                         LA_Chars,            45,
  381.                         LA_Lines,            2,
  382.                         LABX_ReserveSpace,    TRUE,
  383.                         LABX_FirstLabel,    MSG_DIALPANEL_TIMEOUT_TXT,
  384.                         LABX_LastLabel,        MSG_DIALPANEL_ATTEMPT_TXT,
  385.                     TAG_DONE);
  386.  
  387.                     LT_New(Handle,
  388.                         LA_Type,            BOX_KIND,
  389.                         LA_ID,                GAD_NOTE,
  390.                         LA_Chars,            45,
  391.                         LA_Lines,            1,
  392.                         LABX_ReserveSpace,    TRUE,
  393.                         LABX_FirstLabel,    MSG_DIALPANEL_MESSAGE_TXT,
  394.                         LABX_LastLabel,        MSG_DIALPANEL_MESSAGE_TXT,
  395.                     TAG_DONE);
  396.  
  397.                     LT_EndGroup(Handle);
  398.                 }
  399.  
  400.                 LT_New(Handle,
  401.                     LA_Type,    VERTICAL_KIND,
  402.                 TAG_DONE);
  403.                 {
  404.                     LT_New(Handle,
  405.                         LA_Type,        XBAR_KIND,
  406.                     TAG_DONE);
  407.  
  408.                     LT_New(Handle,
  409.                         LA_Type,        CHECKBOX_KIND,
  410.                         LA_LabelID,        MSG_DIALPANEL_RECORD_ON_CONNECTION_TXT,
  411.                         LA_BOOL,        Record,
  412.                     TAG_DONE);
  413.  
  414.                     LT_EndGroup(Handle);
  415.                 }
  416.  
  417.                 LT_EndGroup(Handle);
  418.             }
  419.  
  420.             LT_New(Handle,
  421.                 LA_Type,VERTICAL_KIND,
  422.             TAG_DONE);
  423.             {
  424.                 LT_New(Handle,
  425.                     LA_Type,        XBAR_KIND,
  426.                     LAXB_FullSize,    TRUE,
  427.                 TAG_DONE);
  428.  
  429.                 LT_EndGroup(Handle);
  430.             }
  431.  
  432.             LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  433.                 LAGR_Spread,    TRUE,
  434.             TAG_DONE);
  435.             {
  436.                 LT_New(Handle,
  437.                     LA_Type,        BUTTON_KIND,
  438.                     LA_LabelID,        MSG_DIALPANEL_SKIP_GAD,
  439.                     LA_ID,            GAD_SKIP,
  440.                     LABT_ExtraFat,    TRUE,
  441.                     GA_Disabled,    TRUE,
  442.                 TAG_DONE);
  443.  
  444.                 LT_New(Handle,
  445.                     LA_Type,        BUTTON_KIND,
  446.                     LA_LabelID,        MSG_GLOBAL_REMOVE_GAD,
  447.                     LA_ID,            GAD_REMOVE,
  448.                     LABT_ExtraFat,    TRUE,
  449.                     GA_Disabled,    TRUE,
  450.                 TAG_DONE);
  451.  
  452.                 LT_New(Handle,
  453.                     LA_Type,        BUTTON_KIND,
  454.                     LA_LabelID,        MSG_DIALPANEL_GO_TO_ONLINE_GAD,
  455.                     LA_ID,            GAD_ONLINE,
  456.                     LABT_ReturnKey,    TRUE,
  457.                     LABT_ExtraFat,    TRUE,
  458.                 TAG_DONE);
  459.  
  460.                 LT_New(Handle,
  461.                     LA_Type,        BUTTON_KIND,
  462.                     LA_LabelID,        MSG_GLOBAL_ABORT_GAD,
  463.                     LA_ID,            GAD_ABORT,
  464.                     LABT_ExtraFat,    TRUE,
  465.                 TAG_DONE);
  466.  
  467.                 LT_EndGroup(Handle);
  468.             }
  469.  
  470.             LT_EndGroup(Handle);
  471.         }
  472.  
  473.         if(LT_Build(Handle,
  474.             LAWN_TitleID,        MSG_DIALPANEL_DIALING_TXT,
  475.             LAWN_IDCMP,            IDCMP_CLOSEWINDOW,
  476.             LAWN_HelpHook,        &GuideHook,
  477.             LAWN_Parent,        Window,
  478.             WA_DepthGadget,        TRUE,
  479.             WA_CloseGadget,        TRUE,
  480.             WA_DragBar,            TRUE,
  481.             WA_RMBTrap,            TRUE,
  482.             WA_Activate,        TRUE,
  483. /*            WA_SimpleRefresh,    TRUE,*/
  484.         TAG_DONE))
  485.             return(Handle);
  486.         else
  487.             LT_DeleteHandle(Handle);
  488.     }
  489.  
  490.     return(NULL);
  491. }
  492.  
  493.     /* DialPanel():
  494.      *
  495.      *    This routine opens a small window in the middle of the
  496.      *    console window and walks down the list of numbers to
  497.      *    dial.
  498.      */
  499.  
  500. BOOL
  501. DialPanel()
  502. {
  503.     LayoutHandle    *Handle;
  504.     BOOL             Result = FALSE,
  505.                      Record = FALSE,
  506.                      DropIt = FALSE;
  507.  
  508.     BlockWindows();
  509.  
  510.     if(Handle = OpenDialPanel(&Record))
  511.     {
  512.         STATIC struct SerialSettings OriginalSerialConfig;
  513.  
  514.         struct Window        *PanelWindow = Handle -> Window;
  515.  
  516.         UBYTE                 ExitCommand[80],
  517.                              ExitBuffer[80],
  518.                               InitBuffer[80],
  519.                               PrefixBuffer[80],
  520.                               NumberBuffer[100];
  521.  
  522.         UBYTE                 DialBuffer[300];
  523.  
  524.         STRPTR                 NextExit,
  525.                              NextInit,
  526.                              NextPrefix,
  527.                              NextNumber;
  528.  
  529.         LONG                 NumberCount,
  530.                              NumberCurrent;
  531.  
  532.         LONG                 DialTimeout,
  533.                              DialRetries    = 0,
  534.                              DialAttempt    = 0;
  535.         struct PhoneNode    *DialNode        = NULL;
  536.  
  537.         LONG                 RedialTimeout;
  538.  
  539.         STRPTR                 CallingName;
  540.         UBYTE                 CallingBuffer[80];
  541.  
  542.         BOOL                 Dialing    = FALSE,
  543.                              Calling    = FALSE,
  544.                              Waiting    = FALSE,
  545.                              Skipping    = FALSE,
  546.                              Aborting    = FALSE,
  547.                              Error        = FALSE,
  548.                              Done        = FALSE,
  549.                              NeedHangUp    = TRUE;
  550.  
  551.         LONG                 RunCount    = 0;
  552.  
  553.         ULONG                 ODUMask;
  554.  
  555.             // Don't mix up the line send stuff with the default sending routine
  556.  
  557.         BOOL                (* LocalSendLine)(register STRPTR,register LONG);
  558.  
  559.         LocalSendLine    = SendLine;
  560.         SendLine        = SendLineDial;
  561.  
  562.             // Set up the ODU stuff
  563.  
  564.         if(OwnDevUnitBase && Config -> SerialConfig -> ReleaseODUWhenDialing && Config -> SerialConfig -> SatisfyODURequests != ODU_KEEP && !(Config -> SerialConfig -> Shared && Config -> SerialConfig -> NoODUIfShared) && OwnDevBit != -1)
  565.             ODUMask = (1L << OwnDevBit);
  566.         else
  567.             ODUMask = NULL;
  568.  
  569.             /* Reset the area code scanner data. */
  570.  
  571.         ObtainSemaphore(&PatternSemaphore);
  572.  
  573.         ChosenEntry        = NULL;
  574.         ChosenPattern    = NULL;
  575.  
  576.         ReleaseSemaphore(&PatternSemaphore);
  577.  
  578.             /* We are now dialing. */
  579.  
  580.         Status = STATUS_DIALING;
  581.  
  582.             /* Remember the original serial settings, so we
  583.              * can return to them later.
  584.              */
  585.  
  586.         CopyMem(Config -> SerialConfig,&OriginalSerialConfig,sizeof(struct SerialSettings));
  587.  
  588.             /* Set up the AmigaGuide help context. */
  589.  
  590.         GuideContext(CONTEXT_DIAL);
  591.  
  592.             /* No exit command is defined yet. */
  593.  
  594.         ExitCommand[0] = 0;
  595.  
  596.             /* Make the current one the active one. */
  597.  
  598.         LT_ShowWindow(Handle,TRUE);
  599.  
  600.         PushWindow(PanelWindow);
  601.  
  602.             /* Make a backup of the current configuration. */
  603.  
  604.         SaveConfig(Config,PrivateConfig);
  605.  
  606.             /* Don't echo serial output unless requested by the user. */
  607.  
  608.         if(!Config -> ModemConfig -> VerboseDialing)
  609.             Quiet = TRUE;
  610.  
  611.             /* Perform full sequence check. */
  612.  
  613.         FullCheck = TRUE;
  614.  
  615.             /* Reset the scanner. */
  616.  
  617.         FlowInit(TRUE);
  618.  
  619.             /* Clear the signals. */
  620.  
  621.         SetSignal(0,SIG_SKIP | SIG_BREAK);
  622.  
  623.             /* The big dialing loop. */
  624.  
  625.         do
  626.         {
  627.                 /* Abort the process? */
  628.  
  629.             if(SetSignal(0,SIG_BREAK) & SIG_BREAK)
  630.             {
  631.                 if(!Done)
  632.                     Aborting = Done = TRUE;
  633.             }
  634.  
  635.                 // Check if we should let go of the device
  636.  
  637.             if(ODUMask)
  638.             {
  639.                 if(SetSignal(0,0) & ODUMask)
  640.                 {
  641.                     if(!Done)
  642.                     {
  643.                         Aborting = Done = DropIt = TRUE;
  644.  
  645.                         SetSignal(0,ODUMask);
  646.                     }
  647.                 }
  648.             }
  649.  
  650.                 /* Any window input? */
  651.  
  652.             if(!Done && (SetSignal(0,PORTMASK(PanelWindow -> UserPort)) & PORTMASK(PanelWindow -> UserPort)))
  653.             {
  654.                 struct IntuiMessage    *Msg;
  655.                 ULONG                 MsgClass,
  656.                                      MsgQualifier;
  657.                 UWORD                 MsgCode;
  658.                 struct Gadget        *MsgGadget;
  659.  
  660.                 while(Msg = LT_GetIMsg(Handle))
  661.                 {
  662.                     MsgClass        = Msg -> Class;
  663.                     MsgCode            = Msg -> Code;
  664.                     MsgQualifier    = Msg -> Qualifier;
  665.                     MsgGadget        = Msg -> IAddress;
  666.  
  667.                     LT_ReplyIMsg(Msg);
  668.  
  669.                         /* Convert the space keypress into a
  670.                          * skip command.
  671.                          */
  672.  
  673.                     if(MsgClass == IDCMP_RAWKEY)
  674.                     {
  675.                         if((Dialing || Waiting) && LT_GetCode(MsgQualifier,MsgClass,MsgCode,MsgGadget) == ' ')
  676.                         {
  677.                             LT_PressButton(Handle,GAD_SKIP);
  678.  
  679.                             Skipping = TRUE;
  680.                         }
  681.                     }
  682.  
  683.                         /* Close the window, hang up the line,
  684.                          * return to the phone book.
  685.                          */
  686.  
  687.                     if(MsgClass == IDCMP_CLOSEWINDOW)
  688.                         Aborting = Done = Result = TRUE;
  689.  
  690.                         /* So a button was pressed. */
  691.  
  692.                     if(MsgClass == IDCMP_GADGETUP)
  693.                     {
  694.                         switch(MsgGadget -> GadgetID)
  695.                         {
  696.                                 /* Remove the currently active dialing
  697.                                  * list entry.
  698.                                  */
  699.  
  700.                             case GAD_REMOVE:
  701.  
  702.                                     /* This makes sense only while
  703.                                      * we are dialing.
  704.                                      */
  705.  
  706.                                 if(Dialing)
  707.                                 {
  708.                                     struct PhoneNode    *NextNode = NULL;
  709.                                     BOOL                 UseHangUp;
  710.  
  711.                                         /* If still dialing, hang up first. */
  712.  
  713.                                     if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  714.                                         UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  715.                                     else
  716.                                         UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  717.  
  718.                                     if(UseHangUp)
  719.                                         HangUp();
  720.                                     else
  721.                                     {
  722.                                         SerWrite("\r",1);
  723.  
  724.                                         DelayTime(1,0);
  725.                                     }
  726.  
  727.                                         /* Ignore the response of the modem. */
  728.  
  729.                                     HandleSerial();
  730.  
  731.                                     FlowInit(TRUE);
  732.  
  733.                                         /* Is there another entry in the list? */
  734.  
  735.                                     if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  736.                                         NextNode = (struct PhoneNode *)DialNode -> VanillaNode . ln_Succ;
  737.                                     else
  738.                                     {
  739.                                             /* No, there isn't; do we have a list with
  740.                                              * at least two entries in it?
  741.                                              */
  742.  
  743.                                         if(DialList -> lh_Head -> ln_Succ -> ln_Succ)
  744.                                         {
  745.                                                 /* Yet another dialing attempt coming up... */
  746.  
  747.                                             DialAttempt++;
  748.  
  749.                                                 /* Check for dial retry limit. */
  750.  
  751.                                             if(DialRetries >= 0 && DialAttempt >= DialRetries)
  752.                                             {
  753.                                                 DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  754.  
  755.                                                 WakeUp(PanelWindow,SOUND_BELL);
  756.  
  757.                                                 DelayTime(2,0);
  758.  
  759.                                                 Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  760.  
  761.                                                 Done = TRUE;
  762.                                             }
  763.                                             else
  764.                                             {
  765.                                                     /* Grab first list entry and continue. */
  766.  
  767.                                                 NextNode = (struct PhoneNode *)DialList -> lh_Head;
  768.                                             }
  769.                                         }
  770.                                         else
  771.                                         {
  772.                                                 /* That's all, folks! */
  773.  
  774.                                             DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_LIST_IS_EMPTY_TXT));
  775.  
  776.                                             DelayTime(2,0);
  777.  
  778.                                             Done = TRUE;
  779.                                         }
  780.                                     }
  781.  
  782.                                         /* Remove dial entry from list. */
  783.  
  784.                                     if(DialNode -> Entry)
  785.                                         RemoveDialNode(DialNode);
  786.  
  787.                                     Remove(&DialNode -> VanillaNode);
  788.  
  789.                                     FreeVecPooled(DialNode);
  790.  
  791.                                         /* Is there an entry to proceed with? */
  792.  
  793.                                     if(DialNode = NextNode)
  794.                                     {
  795.                                         NextNumber = NULL;
  796.  
  797.                                         Calling = TRUE;
  798.                                     }
  799.                                 }
  800.  
  801.                                 break;
  802.  
  803.                             case GAD_SKIP:
  804.  
  805.                                 if(Dialing || Waiting)
  806.                                     Skipping = TRUE;
  807.  
  808.                                 break;
  809.  
  810.                             case GAD_ONLINE:
  811.  
  812.                                     /* Go online so soon? */
  813.  
  814.                                 if(!DialNode)
  815.                                 {
  816.                                     DialNode = (struct PhoneNode *)DialList -> lh_Head;
  817.  
  818.                                     if(DialNode -> Entry)
  819.                                         ExtractString(DialNode -> Entry -> Header -> Number,NumberBuffer,TRUE);
  820.                                     else
  821.                                         ExtractString(DialNode -> VanillaNode . ln_Name,NumberBuffer,TRUE);
  822.                                 }
  823.  
  824.                                 Connect(DialNode,NumberBuffer);
  825.  
  826.                                 Done = TRUE;
  827.  
  828.                                 break;
  829.  
  830.                                 /* Abort the dialing process. */
  831.  
  832.                             case GAD_ABORT:
  833.  
  834.                                 Aborting = Done = TRUE;
  835.  
  836.                                 break;
  837.                         }
  838.                     }
  839.  
  840.                     if(Done)
  841.                         break;
  842.                 }
  843.             }
  844.  
  845.                 /* Skip the current action? */
  846.  
  847.             if(SetSignal(0,SIG_SKIP) & SIG_SKIP)
  848.             {
  849.                 if((Dialing || Waiting) && !Done)
  850.                     Skipping = TRUE;
  851.             }
  852.  
  853.                 /* Are we to abort? */
  854.  
  855.             if(Aborting)
  856.             {
  857.                     /* Hang up if necessary. */
  858.  
  859.                 if(Dialing)
  860.                 {
  861.                     BOOL UseHangUp;
  862.  
  863.                     DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ABORTING_TXT));
  864.  
  865.                     if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  866.                         UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  867.                     else
  868.                         UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  869.  
  870.                     if(UseHangUp)
  871.                         HangUp();
  872.                     else
  873.                     {
  874.                         SerWrite("\r",1);
  875.                         DelayTime(1,0);
  876.                     }
  877.  
  878.                         /* Ignore the response of the modem. */
  879.  
  880.                     HandleSerial();
  881.  
  882.                     FlowInit(TRUE);
  883.                 }
  884.             }
  885.  
  886.                 /* Start at the beginning. */
  887.  
  888.             if(!DialNode && !Done)
  889.             {
  890.                 DialNode = (struct PhoneNode *)DialList -> lh_Head;
  891.  
  892.                 LT_SetAttributes(Handle,GAD_SKIP,
  893.                     GA_Disabled,    FALSE,
  894.                 TAG_DONE);
  895.  
  896.                 LT_SetAttributes(Handle,GAD_REMOVE,
  897.                     GA_Disabled,    FALSE,
  898.                 TAG_DONE);
  899.  
  900.                 Calling = TRUE;
  901.  
  902.                 NextNumber = NULL;
  903.             }
  904.  
  905.                 /* Are we to start a call? */
  906.  
  907.             if(Calling && !Done)
  908.             {
  909.                     /* Reset the sequence scanner, the user may have skipped
  910.                      * the previous dial attempt causing the modem to return
  911.                      * `NO CARRIER'. To prevent the dialer from skipping the
  912.                      * next dial entry as well as the previous we have to
  913.                      * flush any data pending on the serial line.
  914.                      */
  915.  
  916.                 FlowInit(TRUE);
  917.  
  918.                     /* Is this the first number for this dial entry? */
  919.  
  920.                 if(!NextNumber)
  921.                 {
  922.                     STRPTR    PhoneNumber;
  923.                     LONG    i,Len;
  924.  
  925.                         /* Does this entry have a configuration attached? */
  926.  
  927.                     if(DialNode -> Entry)
  928.                     {
  929.                             /* Get the phone number. */
  930.  
  931.                         PhoneNumber = DialNode -> Entry -> Header -> Number;
  932.  
  933.                             /* Pick up the modem configuration. */
  934.  
  935.                         if(DialNode -> Entry -> Config -> ModemConfig)
  936.                         {
  937.                             NextInit    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> ModemInit,    InitBuffer,        FALSE);
  938.                             NextExit    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> ModemExit,    ExitBuffer,        FALSE);
  939.                             NextPrefix    = ExtractString(DialNode -> Entry -> Config -> ModemConfig -> DialPrefix,    PrefixBuffer,    FALSE);
  940.                         }
  941.                         else
  942.                         {
  943.                             NextInit    = ExtractString(Config -> ModemConfig -> ModemInit,        InitBuffer,        FALSE);
  944.                             NextExit    = ExtractString(Config -> ModemConfig -> ModemExit,        ExitBuffer,        FALSE);
  945.                             NextPrefix    = ExtractString(Config -> ModemConfig -> DialPrefix,    PrefixBuffer,    FALSE);
  946.                         }
  947.                     }
  948.                     else
  949.                     {
  950.                             /* Get the phone number. */
  951.  
  952.                         PhoneNumber = DialNode -> VanillaNode . ln_Name;
  953.  
  954.                             /* Pick up the modem configuration. */
  955.  
  956.                         if(Config -> ModemConfig -> DoNotSendMainModemCommands)
  957.                             InitBuffer[0] = ExitBuffer[0] = 0;
  958.                         else
  959.                         {
  960.                             NextInit    = ExtractString(Config -> ModemConfig -> ModemInit,        InitBuffer,        FALSE);
  961.                             NextExit    = ExtractString(Config -> ModemConfig -> ModemExit,        ExitBuffer,        FALSE);
  962.                         }
  963.  
  964.                         NextPrefix = ExtractString(Config -> ModemConfig -> DialPrefix,    PrefixBuffer,    FALSE);
  965.                     }
  966.  
  967.                             /* Extract the phone number. */
  968.  
  969.                     NextNumber = ExtractString(PhoneNumber,NumberBuffer,TRUE);
  970.  
  971.                         /* Count the number of phone numbers separated
  972.                          * by "|" characters.
  973.                          */
  974.  
  975.                     Len = strlen(PhoneNumber);
  976.  
  977.                     for(i = 0, NumberCount = 0 ; i < Len ; i++)
  978.                     {
  979.                         if(PhoneNumber[i] == '|')
  980.                         {
  981.                             LONG j;
  982.  
  983.                             for(j = i + 1 ; j <= Len ; j++)
  984.                             {
  985.                                 if(PhoneNumber[j] != ' ' && PhoneNumber[j] != 0)
  986.                                 {
  987.                                     if(PhoneNumber[j] != '|')
  988.                                         NumberCount++;
  989.  
  990.                                     break;
  991.                                 }
  992.                             }
  993.                         }
  994.                     }
  995.  
  996.                         /* This is the first one. */
  997.  
  998.                     NumberCurrent = 0;
  999.                 }
  1000.                 else
  1001.                 {
  1002.                         /* Now for multiple phone numbers separated
  1003.                          * by `|' characters. If `NextNumber' happens
  1004.                          * to be zero, we will prepare to extract
  1005.                          * the first phone number from the list.
  1006.                          * In any other case we will try to obtain
  1007.                          * the next number.
  1008.                          */
  1009.  
  1010.                     NextNumber    = ExtractString(NextNumber,    NumberBuffer,    TRUE);
  1011.                     NextPrefix    = ExtractString(NextPrefix,    PrefixBuffer,    FALSE);
  1012.  
  1013.                     if(!DialNode -> Entry && Config -> ModemConfig -> DoNotSendMainModemCommands)
  1014.                         InitBuffer[0] = ExitBuffer[0] = 0;
  1015.                     else
  1016.                     {
  1017.                         NextInit    = ExtractString(NextInit,    InitBuffer,        FALSE);
  1018.                         NextExit    = ExtractString(NextExit,    ExitBuffer,        FALSE);
  1019.                     }
  1020.  
  1021.                     NumberCurrent++;
  1022.                 }
  1023.  
  1024.                     /* Send the modem exit string before we
  1025.                      * will need to reconfigure the serial
  1026.                      * device driver.
  1027.                      */
  1028.  
  1029.                 if(ExitCommand[0])
  1030.                     Error |= Done |= SendSomeCommand(Handle,ExitCommand,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT),LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1031.  
  1032.                     /* We will need to change the serial parameters
  1033.                      * in order to establish a connection.
  1034.                      */
  1035.  
  1036.                 if(!Done)
  1037.                 {
  1038.                     if(DialNode -> Entry && DialNode -> Entry -> Config -> SerialConfig)
  1039.                     {
  1040.                         if(ReconfigureSerial(PanelWindow,DialNode -> Entry -> Config -> SerialConfig) == RECONFIGURE_FAILURE)
  1041.                         {
  1042.                             WakeUp(PanelWindow,SOUND_ERROR);
  1043.  
  1044.                             Error = Done = TRUE;
  1045.                         }
  1046.                     }
  1047.                     else
  1048.                     {
  1049.                         if(ReconfigureSerial(PanelWindow,&OriginalSerialConfig) == RECONFIGURE_FAILURE)
  1050.                         {
  1051.                             WakeUp(PanelWindow,SOUND_ERROR);
  1052.  
  1053.                             Error = Done = TRUE;
  1054.                         }
  1055.                     }
  1056.                 }
  1057.  
  1058.                 if(!Done)
  1059.                 {
  1060.                         // Update the ODU stuff
  1061.  
  1062.                     if(OwnDevUnitBase && Config -> SerialConfig -> ReleaseODUWhenDialing && Config -> SerialConfig -> SatisfyODURequests != ODU_KEEP && !(Config -> SerialConfig -> Shared && Config -> SerialConfig -> NoODUIfShared) && OwnDevBit != -1)
  1063.                         ODUMask = (1L << OwnDevBit);
  1064.                     else
  1065.                         ODUMask = NULL;
  1066.  
  1067.                         /* Send the modem init command. */
  1068.  
  1069.                     if(InitBuffer[0])
  1070.                         Error |= Done |= SendSomeCommand(Handle,InitBuffer,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT),LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1071.                 }
  1072.  
  1073.                 if(!Done)
  1074.                 {
  1075.                         /* Remember the new exit command. */
  1076.  
  1077.                     strcpy(ExitCommand,ExitBuffer);
  1078.  
  1079.                     if(DialNode -> Entry)
  1080.                         CallingName = DialNode -> Entry -> Header -> Name;
  1081.                     else
  1082.                         CallingName = LocaleString(MSG_GLOBAL_UNKNOWN_TXT);
  1083.  
  1084.                         /* If there is more than one number to follow, say so. */
  1085.  
  1086.                     if(NumberCount)
  1087.                     {
  1088.                         UBYTE LocalBuffer[40];
  1089.  
  1090.                         SPrintf(LocalBuffer,LocaleString(MSG_DIALPANEL_ATTEMPT_OF_TXT),NumberCurrent + 1,NumberCount + 1);
  1091.  
  1092.                         SPrintf(CallingBuffer,"%s (%s)",CallingName,LocalBuffer);
  1093.  
  1094.                         CallingName = CallingBuffer;
  1095.                     }
  1096.  
  1097.                     DialPrintBox(Handle,GAD_CALLING,0,CallingName);
  1098.  
  1099.                         /* Show the comment if any. */
  1100.  
  1101.                     if(DialNode -> Entry && DialNode -> Entry -> Header -> Comment[0])
  1102.                         DialPrintBox(Handle,GAD_CALLING,1,DialNode -> Entry -> Header -> Comment);
  1103.                     else
  1104.                         DialPrintBox(Handle,GAD_CALLING,1,"-");
  1105.  
  1106.                         /* Display the number being called. */
  1107.  
  1108.                     if(DialNode -> Entry)
  1109.                         Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),DialNode -> Entry -> Header -> Name);
  1110.                     else
  1111.                         Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),NumberBuffer);
  1112.  
  1113.                     DialPrintBox(Handle,GAD_CALLING,2,NumberBuffer);
  1114.  
  1115.                         /* Display the name of the service to call next. */
  1116.  
  1117.                     if(NextNumber)
  1118.                     {
  1119.                         if(DialNode -> Entry)
  1120.                             CallingName = DialNode -> Entry -> Header -> Name;
  1121.                         else
  1122.                             CallingName = DialNode -> VanillaNode . ln_Name;
  1123.                     }
  1124.                     else
  1125.                     {
  1126.                         if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  1127.                         {
  1128.                             if(DialNode -> Entry)
  1129.                                 CallingName = ((struct PhoneNode *)DialNode -> VanillaNode . ln_Succ) -> Entry -> Header -> Name;
  1130.                             else
  1131.                                 CallingName = DialNode -> VanillaNode . ln_Succ -> ln_Name;
  1132.                         }
  1133.                         else
  1134.                             CallingName = "-";
  1135.                     }
  1136.  
  1137.                     DialPrintBox(Handle,GAD_CALLING,3,CallingName);
  1138.  
  1139.                         /* Right now we're dialing. */
  1140.  
  1141.                     DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_TXT));
  1142.  
  1143.                         /* Build the dialing command. */
  1144.  
  1145.                     strcpy(DialBuffer,PrefixBuffer);
  1146.  
  1147.                     if(DialNode -> Entry && DialNode -> Entry -> Config -> ModemConfig)
  1148.                     {
  1149.                         if(DialNode -> Entry -> Config -> ModemConfig -> PBX_Mode && DialNode -> Entry -> Config -> ModemConfig -> PBX_Prefix[0])
  1150.                             strcat(DialBuffer,DialNode -> Entry -> Config -> ModemConfig -> PBX_Prefix);
  1151.                     }
  1152.                     else
  1153.                     {
  1154.                         if(Config -> ModemConfig -> PBX_Mode && Config -> ModemConfig -> PBX_Prefix[0])
  1155.                             strcat(DialBuffer,Config -> ModemConfig -> PBX_Prefix);
  1156.                     }
  1157.  
  1158.                     strcat(DialBuffer,NumberBuffer);
  1159.  
  1160.                     if(DialNode -> Entry)
  1161.                     {
  1162.                         if(DialNode -> Entry -> Config -> ModemConfig)
  1163.                             strcat(DialBuffer,DialNode -> Entry -> Config -> ModemConfig -> DialSuffix);
  1164.                         else
  1165.                             strcat(DialBuffer,Config -> ModemConfig -> DialSuffix);
  1166.                     }
  1167.                     else
  1168.                         strcat(DialBuffer,Config -> ModemConfig -> DialSuffix);
  1169.  
  1170.                         /* Pick up dial timeout and dial retries. */
  1171.  
  1172.                     if(DialNode -> Entry && DialNode -> Entry -> Config -> ModemConfig)
  1173.                     {
  1174.                         DialTimeout    = DialNode -> Entry -> Config -> ModemConfig -> DialTimeout;
  1175.                         DialRetries    = DialNode -> Entry -> Config -> ModemConfig -> DialRetries;
  1176.                     }
  1177.                     else
  1178.                     {
  1179.                         DialTimeout    = Config -> ModemConfig -> DialTimeout;
  1180.                         DialRetries    = Config -> ModemConfig -> DialRetries;
  1181.                     }
  1182.  
  1183.                         /* Dial the number. */
  1184.  
  1185.                     SerialCommand(DialBuffer);
  1186.  
  1187.                         /* Now we should be dialing. */
  1188.  
  1189.                     Calling = FALSE;
  1190.                     Dialing = TRUE;
  1191.  
  1192.                         /* For the sake of precision. */
  1193.  
  1194.                     RunCount = 0;
  1195.                 }
  1196.             }
  1197.  
  1198.                 /* Are we to skip the current assignment? */
  1199.  
  1200.             if(Skipping && !Done)
  1201.             {
  1202.                 Skipping = FALSE;
  1203.  
  1204.                     /* Are we currently dialing? */
  1205.  
  1206.                 if(Dialing)
  1207.                 {
  1208.                         /* Hang up if necessary. */
  1209.  
  1210.                     if(NeedHangUp)
  1211.                     {
  1212.                         BOOL UseHangUp;
  1213.  
  1214.                         if(DialNode -> Entry && DialNode -> Entry -> Config && DialNode -> Entry -> Config -> ModemConfig)
  1215.                             UseHangUp = DialNode -> Entry -> Config -> ModemConfig -> AbortHangsUp;
  1216.                         else
  1217.                             UseHangUp = Config -> ModemConfig -> AbortHangsUp;
  1218.  
  1219.                         if(UseHangUp)
  1220.                             HangUp();
  1221.                         else
  1222.                         {
  1223.                             SerWrite("\r",1);
  1224.                             DelayTime(1,0);
  1225.                         }
  1226.                     }
  1227.                     else
  1228.                         NeedHangUp = TRUE;
  1229.  
  1230.                         /* Ignore the response of the modem. */
  1231.  
  1232.                     HandleSerial();
  1233.  
  1234.                     FlowInit(TRUE);
  1235.  
  1236.                         /* Did we dial all the numbers available? */
  1237.  
  1238.                     if(!NextNumber)
  1239.                     {
  1240.                             /* Is this one the last entry? */
  1241.  
  1242.                         if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
  1243.                         {
  1244.                             LONG InterDialDelay;
  1245.  
  1246.                                 /* There is still another entry. */
  1247.  
  1248.                             DialNode = (struct PhoneNode *)DialNode -> VanillaNode . ln_Succ;
  1249.  
  1250.                                 /* Get the inter-dial delay. */
  1251.  
  1252.                             if(DialNode -> Entry)
  1253.                             {
  1254.                                 if(DialNode -> Entry -> Config -> ModemConfig)
  1255.                                     InterDialDelay = DialNode -> Entry -> Config -> ModemConfig -> InterDialDelay;
  1256.                                 else
  1257.                                     InterDialDelay = Config -> ModemConfig -> InterDialDelay;
  1258.                             }
  1259.                             else
  1260.                                 InterDialDelay = Config -> ModemConfig -> InterDialDelay;
  1261.  
  1262.                                 /* Check if we should wait before we fire off another dial command. */
  1263.  
  1264.                             if(InterDialDelay)
  1265.                             {
  1266.                                     /* Wait until the inter-dial delay has elapsed. */
  1267.  
  1268.                                 RedialTimeout = InterDialDelay;
  1269.  
  1270.                                 DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_WAITING_TO_CALL_TXT));
  1271.  
  1272.                                 Dialing = FALSE;
  1273.                                 Waiting = TRUE;
  1274.  
  1275.                                     /* For the sake of precision. */
  1276.  
  1277.                                 RunCount = 0;
  1278.  
  1279.                                 Say(LocaleString(MSG_DIALPANEL_WAITING_TXT));
  1280.  
  1281.                                     /* No entry is currently being called. */
  1282.  
  1283.                                 DialPrintBox(Handle,GAD_CALLING,0,"-");
  1284.                                 DialPrintBox(Handle,GAD_CALLING,1,"-");
  1285.                                 DialPrintBox(Handle,GAD_CALLING,2,"-");
  1286.  
  1287.                                 LT_SetAttributes(Handle,GAD_REMOVE,
  1288.                                     GA_Disabled,    TRUE,
  1289.                                 TAG_DONE);
  1290.  
  1291.                                     /* Display name of entry to call next. */
  1292.  
  1293.                                 if(DialNode -> Entry)
  1294.                                     DialPrintBox(Handle,GAD_CALLING,3,DialNode -> Entry -> Header -> Name);
  1295.                                 else
  1296.                                     DialPrintBox(Handle,GAD_CALLING,3,LocaleString(MSG_GLOBAL_UNKNOWN_TXT));
  1297.                             }
  1298.                             else
  1299.                             {
  1300.                                 Dialing = FALSE;
  1301.                                 Calling = TRUE;
  1302.                             }
  1303.                         }
  1304.                         else
  1305.                         {
  1306.                                 /* Yet another dial attempt coming up. */
  1307.  
  1308.                             DialAttempt++;
  1309.  
  1310.                                 /* Is this one the last dial
  1311.                                  * attempt to be made?
  1312.                                  */
  1313.  
  1314.                             if(DialAttempt >= DialRetries && DialRetries >= 0)
  1315.                             {
  1316.                                 DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  1317.  
  1318.                                 WakeUp(PanelWindow,SOUND_BELL);
  1319.  
  1320.                                 DelayTime(2,0);
  1321.  
  1322.                                 Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  1323.  
  1324.                                 Done = TRUE;
  1325.                             }
  1326.                             else
  1327.                             {
  1328.                                 LONG InterDialDelay;
  1329.  
  1330.                                     /* Get the first list entry. */
  1331.  
  1332.                                 DialNode = (struct PhoneNode *)DialList -> lh_Head;
  1333.  
  1334.                                 NextNumber = NULL;
  1335.  
  1336.                                     /* Get the redial delay. */
  1337.  
  1338.                                 if(DialNode -> Entry)
  1339.                                 {
  1340.                                     if(DialNode -> Entry -> Config -> ModemConfig)
  1341.                                     {
  1342.                                         RedialTimeout    = DialNode -> Entry -> Config -> ModemConfig -> RedialDelay;
  1343.                                         InterDialDelay    = DialNode -> Entry -> Config -> ModemConfig -> InterDialDelay;
  1344.                                     }
  1345.                                     else
  1346.                                     {
  1347.                                         RedialTimeout    = Config -> ModemConfig -> RedialDelay;
  1348.                                         InterDialDelay    = Config -> ModemConfig -> InterDialDelay;
  1349.                                     }
  1350.                                 }
  1351.                                 else
  1352.                                 {
  1353.                                     RedialTimeout    = Config -> ModemConfig -> RedialDelay;
  1354.                                     InterDialDelay    = Config -> ModemConfig -> InterDialDelay;
  1355.                                 }
  1356.  
  1357.                                     /* Check if the inter-dial delay is larger than
  1358.                                      * the redial delay. If so, use the inter-dial delay.
  1359.                                      */
  1360.  
  1361.                                 if(InterDialDelay > RedialTimeout)
  1362.                                     RedialTimeout = InterDialDelay;
  1363.  
  1364.                                     /* No redial delay? Restart dialing... */
  1365.  
  1366.                                 if(!RedialTimeout)
  1367.                                 {
  1368.                                     Dialing = FALSE;
  1369.                                     Calling = TRUE;
  1370.  
  1371.                                     DelayTime(1,0);
  1372.                                 }
  1373.                                 else
  1374.                                 {
  1375.                                         /* Go into redial delay. */
  1376.  
  1377.                                     DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_REDIAL_DELAY_TXT));
  1378.  
  1379.                                     Dialing = FALSE;
  1380.                                     Waiting = TRUE;
  1381.  
  1382.                                         /* For the sake of precision. */
  1383.  
  1384.                                     RunCount = 0;
  1385.  
  1386.                                     Say(LocaleString(MSG_DIALPANEL_WAITING_TXT));
  1387.  
  1388.                                         /* No entry is currently being called. */
  1389.  
  1390.                                     DialPrintBox(Handle,GAD_CALLING,0,"-");
  1391.                                     DialPrintBox(Handle,GAD_CALLING,1,"-");
  1392.                                     DialPrintBox(Handle,GAD_CALLING,2,"-");
  1393.  
  1394.                                     LT_SetAttributes(Handle,GAD_REMOVE,
  1395.                                         GA_Disabled,    TRUE,
  1396.                                     TAG_DONE);
  1397.  
  1398.                                         /* Display name of entry to call next. */
  1399.  
  1400.                                     if(DialNode -> Entry)
  1401.                                         DialPrintBox(Handle,GAD_CALLING,3,DialNode -> Entry -> Header -> Name);
  1402.                                     else
  1403.                                         DialPrintBox(Handle,GAD_CALLING,3,LocaleString(MSG_GLOBAL_UNKNOWN_TXT));
  1404.                                 }
  1405.                             }
  1406.                         }
  1407.                     }
  1408.                     else
  1409.                     {
  1410.                         LONG InterDialDelay;
  1411.  
  1412.                             /* Get the inter-dial delay. */
  1413.  
  1414.                         if(DialNode -> Entry)
  1415.                         {
  1416.                             if(DialNode -> Entry -> Config -> ModemConfig)
  1417.                                 InterDialDelay = DialNode -> Entry -> Config -> ModemConfig -> InterDialDelay;
  1418.                             else
  1419.                                 InterDialDelay = Config -> ModemConfig -> InterDialDelay;
  1420.                         }
  1421.                         else
  1422.                             InterDialDelay = Config -> ModemConfig -> InterDialDelay;
  1423.  
  1424.                             /* Check if we should wait before we fire off another dial command. */
  1425.  
  1426.                         if(InterDialDelay)
  1427.                         {
  1428.                                 /* Wait until the inter-dial delay has elapsed. */
  1429.  
  1430.                             RedialTimeout = InterDialDelay;
  1431.  
  1432.                             DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_WAITING_TO_CALL_TXT));
  1433.  
  1434.                             Dialing = FALSE;
  1435.                             Waiting = TRUE;
  1436.  
  1437.                                 /* For the sake of precision. */
  1438.  
  1439.                             RunCount = 0;
  1440.  
  1441.                             Say(LocaleString(MSG_DIALPANEL_WAITING_TXT));
  1442.  
  1443.                                 /* No entry is currently being called. */
  1444.  
  1445.                             DialPrintBox(Handle,GAD_CALLING,0,"-");
  1446.                             DialPrintBox(Handle,GAD_CALLING,1,"-");
  1447.                             DialPrintBox(Handle,GAD_CALLING,2,"-");
  1448.  
  1449.                             LT_SetAttributes(Handle,GAD_REMOVE,
  1450.                                 GA_Disabled,    TRUE,
  1451.                             TAG_DONE);
  1452.  
  1453.                                 /* Display name of entry to call next. */
  1454.  
  1455.                             if(DialNode -> Entry)
  1456.                                 DialPrintBox(Handle,GAD_CALLING,3,DialNode -> Entry -> Header -> Name);
  1457.                             else
  1458.                                 DialPrintBox(Handle,GAD_CALLING,3,LocaleString(MSG_GLOBAL_UNKNOWN_TXT));
  1459.                         }
  1460.                         else
  1461.                         {
  1462.                             Dialing = FALSE;
  1463.                             Calling = TRUE;
  1464.                         }
  1465.                     }
  1466.                 }
  1467.                 else
  1468.                 {
  1469.                         /* Stop waiting. */
  1470.  
  1471.                     if(Waiting)
  1472.                     {
  1473.                         LT_SetAttributes(Handle,GAD_REMOVE,
  1474.                             GA_Disabled,    FALSE,
  1475.                         TAG_DONE);
  1476.  
  1477.                         Waiting = FALSE;
  1478.                         Calling = TRUE;
  1479.                     }
  1480.                 }
  1481.             }
  1482.  
  1483.                 /* Take care of serial input. */
  1484.  
  1485.             if(!Done)
  1486.                 HandleSerial();
  1487.  
  1488.                 /* Any news from the modem? */
  1489.  
  1490.             if(!Done && FlowInfo . Changed)
  1491.             {
  1492.                     /* Current number is busy. */
  1493.  
  1494.                 if(FlowInfo . Busy || (FlowInfo . NoCarrier && Config -> ModemConfig -> NoCarrierIsBusy))
  1495.                 {
  1496.                     FlowInit(TRUE);
  1497.  
  1498.                     if(Dialing && !Done)
  1499.                     {
  1500.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
  1501.  
  1502.                         Say(LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
  1503.  
  1504.                         DelayTime(1,0);
  1505.  
  1506.                         Skipping = TRUE;
  1507.  
  1508.                         NeedHangUp = FALSE;
  1509.                     }
  1510.                 }
  1511.  
  1512.                     /* Line does not feature a dialtone. */
  1513.  
  1514.                 if(FlowInfo . NoDialTone)
  1515.                 {
  1516.                     FlowInit(TRUE);
  1517.  
  1518.                     if(Dialing && !Done)
  1519.                     {
  1520.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
  1521.  
  1522.                         WakeUp(PanelWindow,SOUND_ERROR);
  1523.  
  1524.                         Say(LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
  1525.  
  1526.                         Error = Done = TRUE;
  1527.                     }
  1528.                 }
  1529.  
  1530.                     /* Somebody tries to call us. */
  1531.  
  1532.                 if(FlowInfo . Ring)
  1533.                 {
  1534.                     FlowInit(TRUE);
  1535.  
  1536.                     if(!Done)
  1537.                     {
  1538.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1539.  
  1540.                         WakeUp(PanelWindow,SOUND_RING);
  1541.  
  1542.                         Say(LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1543.  
  1544.                         Error = Done = TRUE;
  1545.                     }
  1546.                 }
  1547.  
  1548.                     /* Somebody's talking. */
  1549.  
  1550.                 if(FlowInfo . Voice)
  1551.                 {
  1552.                     FlowInit(TRUE);
  1553.  
  1554.                     if(!Done)
  1555.                     {
  1556.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
  1557.  
  1558.                         WakeUp(PanelWindow,SOUND_VOICE);
  1559.  
  1560.                         Say(LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
  1561.  
  1562.                         Error = Done = TRUE;
  1563.                     }
  1564.                 }
  1565.  
  1566.                     /* We got a connect. */
  1567.  
  1568.                 if(FlowInfo . Connect)
  1569.                 {
  1570.                     FlowInit(TRUE);
  1571.  
  1572.                     if(Dialing && !Done)
  1573.                     {
  1574.                             /* Make the connection. */
  1575.  
  1576.                         Connect(DialNode,NumberBuffer);
  1577.  
  1578.                         Done = TRUE;
  1579.  
  1580.                             /* Wake the user up. */
  1581.  
  1582.                         if(BaudBuffer[0])
  1583.                         {
  1584.                             DialPrintBox(Handle,GAD_NOTE,0,"CONNECT %s",BaudBuffer);
  1585.  
  1586.                             WakeUp(PanelWindow,SOUND_CONNECT);
  1587.  
  1588.                             DelayTime(2,0);
  1589.  
  1590.                                 /* Install new baud rate if desired. */
  1591.  
  1592.                             if(Config -> ModemConfig -> ConnectAutoBaud && DTERate > 110)
  1593.                             {
  1594.                                 Config -> SerialConfig -> BaudRate = DTERate;
  1595.  
  1596.                                 ReconfigureSerial(PanelWindow,NULL);
  1597.                             }
  1598.                         }
  1599.                         else
  1600.                         {
  1601.                             DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
  1602.  
  1603.                             WakeUp(PanelWindow,SOUND_CONNECT);
  1604.                         }
  1605.  
  1606.                         Say(LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
  1607.                     }
  1608.                 }
  1609.  
  1610.                     /* Looks like an error. */
  1611.  
  1612.                 if(FlowInfo . Error)
  1613.                 {
  1614.                     FlowInit(TRUE);
  1615.  
  1616.                     if(Dialing && !Done)
  1617.                     {
  1618.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1619.  
  1620.                         WakeUp(PanelWindow,SOUND_ERROR);
  1621.  
  1622.                         Error = Done = TRUE;
  1623.                     }
  1624.                 }
  1625.  
  1626.                     /* In any other case, reset the scanner. */
  1627.  
  1628.                 FlowInit(TRUE);
  1629.             }
  1630.  
  1631.                 /* If nothing special's up... */
  1632.  
  1633.             if(!Done && !Skipping && (Dialing || Waiting))
  1634.             {
  1635.                     /* Wait half a second. */
  1636.  
  1637.                 DelayTime(0,MILLION / 2);
  1638.  
  1639.                 if(Dialing)
  1640.                 {
  1641.                     DialPrintBox(Handle,GAD_TIME,0,"%2ld:%02ld",DialTimeout / 60,DialTimeout % 60);
  1642.  
  1643.                     if(DialRetries < 0)
  1644.                         DialPrintBox(Handle,GAD_TIME,1,LocaleString(MSG_DIAL_RETRIES_UNLIMITED_TXT));
  1645.                     else
  1646.                         DialPrintBox(Handle,GAD_TIME,1,LocaleString(MSG_DIALPANEL_ATTEMPT_OF_TXT),DialAttempt + 1,DialRetries);
  1647.                 }
  1648.  
  1649.                 if(Waiting)
  1650.                     DialPrintBox(Handle,GAD_TIME,0,"%2ld:%02ld",RedialTimeout / 60,RedialTimeout % 60);
  1651.  
  1652.                     /* The following instructions are executed each second */
  1653.  
  1654.                 if(RunCount++)
  1655.                 {
  1656.                     RunCount = 0;
  1657.  
  1658.                         /* Are we dialing? */
  1659.  
  1660.                     if(Dialing)
  1661.                     {
  1662.                             /* Yet another second has elapsed. */
  1663.  
  1664.                         if(DialTimeout > 0)
  1665.                             DialTimeout--;
  1666.  
  1667.                             /* Has the dial timeout elapsed without
  1668.                              * a connection being made?
  1669.                              */
  1670.  
  1671.                         if(!DialTimeout)
  1672.                         {
  1673.                             DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIAL_ATTEMPT_TIMEOUT_TXT));
  1674.  
  1675.                             Skipping = TRUE;
  1676.                         }
  1677.                     }
  1678.  
  1679.                         /* Are we waiting? */
  1680.  
  1681.                     if(Waiting)
  1682.                     {
  1683.                             /* Yet another second has elapsed. */
  1684.  
  1685.                         if(RedialTimeout > 0)
  1686.                             RedialTimeout--;
  1687.  
  1688.                             /* The redial delay has elapsed,
  1689.                              * start dialing again.
  1690.                              */
  1691.  
  1692.                         if(!RedialTimeout)
  1693.                             Skipping = TRUE;
  1694.                     }
  1695.                 }
  1696.             }
  1697.         }
  1698.         while(!Done);
  1699.  
  1700.             /* Are we online or not? */
  1701.  
  1702.         if(!Online)
  1703.         {
  1704.             BOOL SendCommands = TRUE;
  1705.  
  1706.                 /* Is the serial setup different? */
  1707.  
  1708.             if(memcmp(Config -> SerialConfig,&OriginalSerialConfig,sizeof(struct SerialSettings)))
  1709.             {
  1710.                     /* Set up the old serial configuration. */
  1711.  
  1712.                 if(ReconfigureSerial(PanelWindow,&OriginalSerialConfig) == RECONFIGURE_FAILURE)
  1713.                     SendCommands = FALSE;
  1714.             }
  1715.  
  1716.             if(SendCommands)
  1717.             {
  1718.                     /* Send the exit command if necessary. */
  1719.  
  1720.                 if(ExitCommand[0])
  1721.                     Error |= SendSomeCommand(Handle,ExitCommand,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT),LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1722.  
  1723.                     /* Take care of the init command if necessary. */
  1724.  
  1725.                 if(Config -> ModemConfig -> ModemInit[0] && !Error)
  1726.                     Error |= SendSomeCommand(Handle,Config -> ModemConfig -> ModemInit,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT),LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1727.             }
  1728.         }
  1729.  
  1730.             /* Make sure the error gets displayed. */
  1731.  
  1732.         if(Error && !DropIt)
  1733.         {
  1734.             struct IntuiMessage    *Msg;
  1735.             ULONG                 MsgClass;
  1736.             LONG                 i;
  1737.  
  1738.             for(i = GAD_SKIP ; i <= GAD_REMOVE ; i++)
  1739.                 LT_SetAttributes(Handle,i,GA_Disabled,TRUE,TAG_DONE);
  1740.  
  1741.             Done = FALSE;
  1742.  
  1743.             do
  1744.             {
  1745.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  1746.                     break;
  1747.  
  1748.                 while(Msg = LT_GetIMsg(Handle))
  1749.                 {
  1750.                     MsgClass = Msg -> Class;
  1751.  
  1752.                     LT_ReplyIMsg(Msg);
  1753.  
  1754.                     if(MsgClass == IDCMP_CLOSEWINDOW || MsgClass == IDCMP_GADGETUP)
  1755.                         Done = TRUE;
  1756.                 }
  1757.             }
  1758.             while(!Done);
  1759.         }
  1760.  
  1761.             // Put back the old routine if necessary
  1762.  
  1763.         if(SendLine == SendLineDial)
  1764.             SendLine = LocalSendLine;
  1765.  
  1766.         PopWindow();
  1767.  
  1768.         LT_DeleteHandle(Handle);
  1769.  
  1770.             /* Reset the scanner. */
  1771.  
  1772.         FullCheck = FALSE;
  1773.  
  1774.         FlowInit(TRUE);
  1775.  
  1776.             /* We are done now, restart echoing serial */
  1777.  
  1778.         Quiet = FALSE;
  1779.  
  1780.         ReleaseWindows();
  1781.  
  1782.             /* Reset the display if necessary. */
  1783.  
  1784.         if(ResetDisplay)
  1785.         {
  1786.             if(!DisplayReset())
  1787.                 return(FALSE);
  1788.         }
  1789.  
  1790.             /* Handle online jobs. */
  1791.  
  1792.         if(Online)
  1793.         {
  1794.             SetDialMenu(FALSE);
  1795.  
  1796.                 /* Send the startup macro if necessary. */
  1797.  
  1798.             if(SendStartup)
  1799.             {
  1800.                 if(Config -> CommandConfig -> LoginMacro[0])
  1801.                     SerialCommand(Config -> CommandConfig -> LoginMacro);
  1802.  
  1803.                 if(Config -> CommandConfig -> StartupMacro[0])
  1804.                     SerialCommand(Config -> CommandConfig -> StartupMacro);
  1805.  
  1806.                 SendStartup = FALSE;
  1807.             }
  1808.  
  1809.                 /* Take care of the recording feature. */
  1810.  
  1811.             if(Record)
  1812.             {
  1813.                 if(CreateRecord(CurrentBBSName[0] ? CurrentBBSName : CurrentBBSNumber))
  1814.                 {
  1815.                     RememberResetOutput();
  1816.                     RememberResetInput();
  1817.  
  1818.                     RememberOutput = TRUE;
  1819.  
  1820.                     Recording = TRUE;
  1821.                     RecordingLine = FALSE;
  1822.  
  1823.                     OnItem(MEN_RECORD_LINE);
  1824.  
  1825.                     CheckItem(MEN_RECORD,TRUE);
  1826.                     CheckItem(MEN_RECORD_LINE,FALSE);
  1827.                 }
  1828.             }
  1829.         }
  1830.         else
  1831.             SetDialMenu(TRUE);
  1832.     }
  1833.     else
  1834.         ReleaseWindows();
  1835.  
  1836.         /* Reply to the message that started the
  1837.          * dialing process.
  1838.          */
  1839.  
  1840.     Forbid();
  1841.  
  1842.     if(DialMsg)
  1843.     {
  1844.         if(Online)
  1845.             DialMsg -> rm_Result1 = RC_OK;
  1846.         else
  1847.             DialMsg -> rm_Result1 = RC_WARN;
  1848.  
  1849.         DialMsg -> rm_Result2 = 0;
  1850.  
  1851.         ReplyMsg(DialMsg);
  1852.  
  1853.         DialMsg = NULL;
  1854.     }
  1855.  
  1856.     Permit();
  1857.  
  1858.     if(DropIt)
  1859.         HandleOwnDevUnit();
  1860.  
  1861.     return(Result);
  1862. }
  1863.